package jwdt.xadmin.system.action;

import jwdt.common.action.BaseAction;
import jwdt.common.util.CacheUtil;
import jwdt.xadmin.system.bean.TDep;
import jwdt.xadmin.system.service.DeptManageService;

import com.ezerg.db.Jdb;
import com.ezerg.db.ext.PageUtil;
import com.ezerg.web.Form;
import com.ezerg.web.Module;
import com.ezerg.web.Page;
import com.ezerg.web.annotation.Controller;
import com.ezerg.web.annotation.RequestMapping;

@Controller("/xadmin/system")
public class DeptManagerAction extends BaseAction {
	
	private DeptManageService deptManageService = (DeptManageService)app.getBean("deptManageService");

	@RequestMapping("/listDeptForCombox")
	public Page doListDeptForCombox(Form f, Module m) throws Exception {
		//生成json字符串
    	return m.getJsonPage(f, Jdb.get().query("select id, name from t_dep ORDER BY px,id asc", CacheUtil.C0));
	}
	
	@RequestMapping("/listDept")
	public Page doListDept(Form f, Module m) throws Exception {
		PageUtil pu = (PageUtil)f.copy2Class(PageUtil.class);
		return m.getWritePage(f, deptManageService.doListDept(pu));
	}
	
	@RequestMapping("/addDept")
	public Page doAddact(Form f, Module m) throws Exception {
		TDep obj = (TDep)f.copy2Class(TDep.class);
		return m.getWritePage(f, deptManageService.doAddact(obj));
	}
	
	@RequestMapping("/editDept")
	public Page doEditact(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		TDep obj = (TDep)f.copy2Class(TDep.class);
		return m.getWritePage(f, deptManageService.doEditact(obj, id));
	}
	
	@RequestMapping("/delDept")
	public Page doDel(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		return m.getWritePage(f, deptManageService.doDelact(id));
	}
	
	@RequestMapping("/deptWindow")
	public Page doLoad(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		f.add("obj", deptManageService.doLoad(id));
		return m.findPage("/xadmin/system/deptWindow");
	}
	
	@RequestMapping("/updateDeptState")
	public Page doUpdateDeptState(Form f, Module m) throws Exception {
		int id = f.getInt("id");
		int result = f.getInt("result");
		return m.getWritePage(f, deptManageService.doUpdateState(id,"zt="+result));
	}
	
	@RequestMapping("/listDeptForTree")
	public Page doListForTree(Form f, Module m) throws Exception {
    	return m.getWritePage(f, deptManageService.doListDepForTree());
	}
	
	@RequestMapping("/listDeptForCombox")
	public Page doListForCombox(Form f, Module m) throws Exception {
    	return m.getJsonPage(f, Jdb.get().query("SELECT id,NAME FROM t_dep ORDER BY px"));
	}
}
